package com.fadis.data.base;

import java.util.Arrays;

public class FadisString2 implements Comparable<FadisString2>, IBaseData{

    private byte[] str;

    public byte[] getStr() {
        return str;
    }

    public void setStr(byte[] str) {
        this.str = str;
    }

    public FadisString2(byte[] str) {
        this.str = str;
    }



    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        FadisString2 that = (FadisString2) o;
        return Arrays.equals(str, that.str);
    }

    @Override
    public int hashCode() {
        return Arrays.hashCode(str);
    }

    @Override
    public int compareTo(FadisString2 o) {
        if (this == o) return 0;
        if (o == null) return 1;
        if(Arrays.equals(str, o.str)) return 0;
        if(str.length < o.str.length) return -1;
        if(str.length > o.str.length) return 1;
        for (int i = 0; i < str.length; i++) {
            if(str[i] > o.str[i]) return 1;
            if(str[i] < o.str[i]) return -1;
        }
        return 0;
    }

//    public static void main(String[] args) {
//        String s = "ddd的的";
//        System.out.println(s.length());  // 5
//        System.out.println(SafeEncoder.encode(s).length); // 9 = 3 + 6
//    }
}
